﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CCWin.SkinControl;
using System.Drawing;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;

namespace SafeSave
{

    class Helper
    {

    }

    class FileMessage
    {
        public int fileNum = 0;
        public List<string> fileNames = new List<string>();
        public List<string> fileID = new List<string>();
    }

    class UserData
    {
        public string id;
        public ChatListSubItem item;//个人信息
        public List<string> tags;//个人标签
        public bool isOnlie;//是否在线
        public int etherCoin;
        //等等
        public FileMessage uploadsFiles = new FileMessage();//上传的文件信息
        public FileMessage downloadFiles = new FileMessage();//下载的文件信息
        public string account_address;
        public string url;

        public UserData(ChatListSubItem userItem)
        {
            this.item = userItem;
        }

        
    }

    class User
    {
        public static UserData user;
    }

    class HttpHelper
    {
        /// <summary>
        /// 发送请求的方法
        /// </summary>
        /// <param name="Url">地址</param>
        /// <param name="postDataStr">数据</param>
        /// <returns></returns>
        public string HttpPost(string Url, string postDataStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
            Stream myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
            myStreamWriter.Write(postDataStr);
            myStreamWriter.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

        public string HttpGet(string Url, string postDataStr)
        {
            String text = (Url + (postDataStr == "" ? "" : "?") + postDataStr);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }
    }

    class LoginJobject_key
    {
        public string account_private_key;
    }
    class LoginJobject_account
    {
        public string account_address;
        public string keyword;

    }
    class UploadFileJobject
    {
        public string file_name;
        public List<string> keywords;
        public List<string> policy;
        public string content;
    }
    class DownloadFileJobject
    {
        public string transaction_id;
    }
    class ApplyRightJobject
    {
        public string address;
        public string time;
        public string ex_msg;
    }
    class AurthorizeJobject
    {
        public string address;
        public bool agree;
        public List<string> attributes;//base
    }
    class SendRegistrationJobject
    {
        public string target_ip;
        public string extra_message;
    }
    class SearchJobject
    {
        public string account_address;
        public List<string> tokens;
    }
}
